package com.refactoring.demo.chapter01;

import com.refactoring.demo.chapter01.price.ChildrensPrice;
import com.refactoring.demo.chapter01.price.NewReleasePrice;
import com.refactoring.demo.chapter01.price.Price;
import com.refactoring.demo.chapter01.price.RegularPrice;

/**
 * 影片
 *
 * @作者：刘富国
 * @创建时间：2017/12/20 16:54
 */
public class Movie {

    /**
     * 儿童影片
     */
    public static final int CHILDRENS = 2;

    /**
     * 普通影片
     */
    public static final int REGULAR = 0;

    /**
     * 新影片
     */
    public static final int NEW_RELEASE = 1;

    /**
     * 影片名字
     */
    private String title;

    /**
     * 影片类型代码
     */
    private int priceCode;

    private Price price;

    public Movie(String title, int priceCode) {
        this.title = title;
        setPriceCode(priceCode);
    }

    public String getTitle() {
        return title;
    }


    public int getPriceCode() {
        return priceCode;
    }

    public void setPriceCode(int priceCode) {
        switch (priceCode) {
            case REGULAR:
                price = new RegularPrice();
                break;
            case CHILDRENS:
                price = new ChildrensPrice();
                break;
            case NEW_RELEASE:
                price = new NewReleasePrice();
                break;
            default:
                throw new IllegalArgumentException("错误的priceCode！");
        }
    }

    public Movie get_movie() {
        return this;
    }

    /**
     * 计算影片费用
     */
    public double getCharge(Integer daysRented) {
        return price.getCharge(daysRented);
    }

    /**
     * 计算常客积分点
     */
    public int getFreqRenterPoints(Integer daysRented) {
        return price.getFreqRenterPoints(daysRented);
    }
}
